import pymysql
import threading

L = threading.Lock()

class DB:
    def __init__(self):
        self.conn = pymysql.connect(host="localhost",port=3306,user="root",password="liujiaqing110",db="p9db",charset="utf8",cursorclass=pymysql.cursors.DictCursor)
        self.cursor = self.conn.cursor()
    def find(self,sql):
        L.acquire()
        self.cursor.execute(sql)
        L.release()
        return self.cursor.fetchone()

    def find_all(self,sql):
        L.acquire()
        self.cursor.execute(sql)
        L.release()
        return self.cursor.fetchall()

    def update(self,sql):
        self.cursor.execute(sql)
        self.conn.commit()
        
    def close(self,sql):
        self.cursor.close()
        self.conn.close()

db1 = DB()